package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.entity.UserFavorite;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserFavoriteMapper {

    @Insert("INSERT INTO user_favorites (user_id, question_id, create_time) VALUES (#{userId}, #{questionId}, #{createTime})")
    int insert(UserFavorite favorite);

    @Delete("DELETE FROM user_favorites WHERE user_id = #{userId} AND question_id = #{questionId}")
    int delete(@Param("userId") int userId, @Param("questionId") int questionId);

    @Select("SELECT COUNT(*) FROM user_favorites WHERE user_id = #{userId} AND question_id = #{questionId}")
    int isFavorited(@Param("userId") int userId, @Param("questionId") int questionId);
}
